home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_419 / yacc / src.lzh / Src / RCS / defs.h,v < prev    next >
Text File  |  1990-07-14  |  6KB  |  329 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.07.14.21.41.27;  author loftus;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.07.14.18.55.21;  author loftus;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @changed char *mallocs to void *mallocs.
  27. @
  28. text
  29. @#include <assert.h>
  30. #include <ctype.h>
  31. #include <stdio.h>
  32.  
  33.  
  34. /*  machine dependent definitions            */
  35. /*  the following definitions are for the VAX        */
  36. /*  they might have to be changed for other machines    */
  37.  
  38. /*  MAXCHAR is the largest unsigned character value    */
  39. /*  MAXSHORT is the largest value of a C short        */
  40. /*  MINSHORT is the most negative value of a C short    */
  41. /*  MAXTABLE is the maximum table size            */
  42. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  43. /*  WORDSIZE computes the number of words needed to    */
  44. /*    store n bits                    */
  45. /*  BIT returns the value of the n-th bit starting    */
  46. /*    from r (0-indexed)                */
  47. /*  SETBIT sets the n-th bit starting from r        */
  48.  
  49. #define    MAXCHAR        255
  50. #define    MAXSHORT    32767
  51. #define MINSHORT    -32768
  52. #define MAXTABLE    32500
  53. #define BITS_PER_WORD    32
  54. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  55. #define    BIT(r, n)    ((((r)[(n)>>5])>>((n)&31))&1)
  56. #define    SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  57.  
  58.  
  59. /*  character names  */
  60.  
  61. #define    NUL        '\0'    /*  the null character  */
  62. #define    NEWLINE        '\n'    /*  line feed  */
  63. #define    SP        ' '     /*  space  */
  64. #define    BS        '\b'    /*  backspace  */
  65. #define    HT        '\t'    /*  horizontal tab  */
  66. #define    VT        '\013'  /*  vertical tab  */
  67. #define    CR        '\r'    /*  carriage return  */
  68. #define    FF        '\f'    /*  form feed  */
  69. #define    QUOTE        '\''    /*  single quote  */
  70. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  71. #define    BACKSLASH    '\\'    /*  backslash  */
  72.  
  73.  
  74. /* defines for constructing filenames */
  75.  
  76. #define    DEFINES_SUFFIX    ".tab.h"
  77. #define    OUTPUT_SUFFIX    ".tab.c"
  78. #define    VERBOSE_SUFFIX    ".output"
  79.  
  80.  
  81. /* keyword codes */
  82.  
  83. #define TOKEN 0
  84. #define LEFT 1
  85. #define RIGHT 2
  86. #define NONASSOC 3
  87. #define MARK 4
  88. #define TEXT 5
  89. #define TYPE 6
  90. #define START 7
  91. #define UNION 8
  92. #define IDENT 9
  93.  
  94.  
  95. /*  symbol classes  */
  96.  
  97. #define UNKNOWN 0
  98. #define TERM 1
  99. #define NONTERM 2
  100.  
  101.  
  102. /*  the undefined value  */
  103.  
  104. #define UNDEFINED (-1)
  105.  
  106.  
  107. /*  action codes  */
  108.  
  109. #define SHIFT 1
  110. #define REDUCE 2
  111. #define ERROR 3
  112.  
  113.  
  114. /*  character macros  */
  115.  
  116. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  117. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  118. #define    NUMERIC_VALUE(c)    ((c) - '0')
  119.  
  120.  
  121. /*  symbol macros  */
  122.  
  123. #define ISTOKEN(s)    ((s) < start_symbol)
  124. #define ISVAR(s)    ((s) >= start_symbol)
  125.  
  126.  
  127. /*  storage allocation macros  */
  128.  
  129. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  130. #define    FREE(x)        (free((char*)(x)))
  131. #define MALLOC(n)    (malloc((unsigned)(n)))
  132. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  133. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  134. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  135.  
  136.  
  137. /*  the structure of a symbol table entry  */
  138.  
  139. typedef struct bucket bucket;
  140. struct bucket
  141. {
  142.     struct bucket *link;
  143.     struct bucket *next;
  144.     char *name;
  145.     char *tag;
  146.     short value;
  147.     short index;
  148.     short prec;
  149.     char class;
  150.     char assoc;
  151. };
  152.  
  153.  
  154. /*  the structure of the LR(0) state machine  */
  155.  
  156. typedef struct core core;
  157. struct core
  158. {
  159.     struct core *next;
  160.     struct core *link;
  161.     short number;
  162.     short accessing_symbol;
  163.     short nitems;
  164.     short items[1];
  165. };
  166.  
  167.  
  168. /*  the structure used to record shifts  */
  169.  
  170. typedef struct shifts shifts;
  171. struct shifts
  172. {
  173.     struct shifts *next;
  174.     short number;
  175.     short nshifts;
  176.     short shift[1];
  177. };
  178.  
  179.  
  180. /*  the structure used to store reductions  */
  181.  
  182. typedef struct reductions reductions;
  183. struct reductions
  184. {
  185.     struct reductions *next;
  186.     short number;
  187.     short nreds;
  188.     short rules[1];
  189. };
  190.  
  191.  
  192. /*  the structure used to represent parser actions  */
  193.  
  194. typedef struct action action;
  195. struct action
  196. {
  197.     struct action *next;
  198.     short symbol;
  199.     short number;
  200.     short prec;
  201.     char action_code;
  202.     char assoc;
  203.     char suppressed;
  204. };
  205.  
  206.  
  207. /* global variables */
  208.  
  209. extern char dflag;
  210. extern char lflag;
  211. extern char tflag;
  212. extern char vflag;
  213.  
  214. extern char *myname;
  215. extern char *cptr;
  216. extern char *line;
  217. extern int lineno;
  218. extern int outline;
  219.  
  220. extern char *banner[];
  221. extern char *header[];
  222. extern char *body[];
  223. extern char *trailer[];
  224.  
  225. extern char *action_file_name;
  226. extern char *defines_file_name;
  227. extern char *input_file_name;
  228. extern char *output_file_name;
  229. extern char *text_file_name;
  230. extern char *union_file_name;
  231. extern char *verbose_file_name;
  232.  
  233. extern FILE *action_file;
  234. extern FILE *defines_file;
  235. extern FILE *input_file;
  236. extern FILE *output_file;
  237. extern FILE *text_file;
  238. extern FILE *union_file;
  239. extern FILE *verbose_file;
  240.  
  241. extern int nitems;
  242. extern int nrules;
  243. extern int nsyms;
  244. extern int ntokens;
  245. extern int nvars;
  246. extern int ntags;
  247.  
  248. extern char unionized;
  249. extern char line_format[];
  250.  
  251. extern int   start_symbol;
  252. extern char  **symbol_name;
  253. extern short *symbol_value;
  254. extern short *symbol_prec;
  255. extern char  *symbol_assoc;
  256.  
  257. extern short *ritem;
  258. extern short *rlhs;
  259. extern short *rrhs;
  260. extern short *rprec;
  261. extern char  *rassoc;
  262.  
  263. extern short **derives;
  264. extern char *nullable;
  265.  
  266. extern bucket *first_symbol;
  267. extern bucket *last_symbol;
  268.  
  269. extern int nstates;
  270. extern core *first_state;
  271. extern shifts *first_shift;
  272. extern reductions *first_reduction;
  273. extern short *accessing_symbol;
  274. extern core **state_table;
  275. extern shifts **shift_table;
  276. extern reductions **reduction_table;
  277. extern unsigned *LA;
  278. extern short *LAruleno;
  279. extern short *lookaheads;
  280. extern short *goto_map;
  281. extern short *from_state;
  282. extern short *to_state;
  283.  
  284. extern action **parser;
  285. extern int SRtotal;
  286. extern int RRtotal;
  287. extern short *SRconflicts;
  288. extern short *RRconflicts;
  289. extern short *defred;
  290. extern short *rules_used;
  291. extern short nunused;
  292. extern short final_state;
  293.  
  294. /* global functions */
  295.  
  296. extern char *allocate();
  297. extern bucket *lookup();
  298. extern bucket *make_bucket();
  299.  
  300.  
  301. /* system variables */
  302.  
  303. extern int errno;
  304.  
  305.  
  306. /* system functions */
  307.  
  308. extern void free();
  309. extern char *calloc();
  310. #ifdef AMIGA
  311. extern void *malloc();
  312. extern void *realloc();
  313. #else
  314. extern char *malloc();
  315. extern char *realloc();
  316. #endif
  317. extern char *strcpy();
  318. @
  319.  
  320.  
  321. 1.1
  322. log
  323. @Initial revision
  324. @
  325. text
  326. @d282 4
  327. d288 1
  328. @
  329.